﻿@model BackInStockSubscribeModel
@using Nop.Web.Models.Catalog;
@{
    Layout = "~/Views/Shared/_Root.cshtml";
}
@using (Html.BeginForm())
{
    <div class="page back-in-stock-subscription-page">
        <div class="page-title">
            <h1>
                @if (Model.AlreadySubscribed)
                {
                    @T("BackInStockSubscriptions.AlreadySubscribed")
                }
                else
                {
                    @T("BackInStockSubscriptions.PopupTitle")
                }
            </h1>
        </div>
        <div class="page-body">
            <div>
                <a href="@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })">@Model.ProductName</a>
            </div>
            <div>
                @if (!Model.SubscriptionAllowed)
                {
                    <div>
                        @T("BackInStockSubscriptions.NotAllowed")</div>
                }
                else if (!Model.IsCurrentCustomerRegistered)
                {
                    <div>
                        @T("BackInStockSubscriptions.OnlyRegistered")</div>
                }
                else if (!Model.AlreadySubscribed && Model.CurrentNumberOfBackInStockSubscriptions >= Model.MaximumBackInStockSubscriptions)
                {
                    <div>
                        @string.Format(T("BackInStockSubscriptions.MaxSubscriptions").Text, Model.MaximumBackInStockSubscriptions)</div>
                }
                else
                {
                    if (!Model.AlreadySubscribed)
                    {
                    <div class="tooltip">@T("BackInStockSubscriptions.Tooltip")</div>
                    }
                    <input type="submit" id="back-in-stock-notify-me" value="@(Model.AlreadySubscribed ? @T("BackInStockSubscriptions.Unsubscribe").Text : @T("BackInStockSubscriptions.NotifyMe").Text)" />

                    <script type="text/javascript">
                    $(function () {
                        $('#back-in-stock-notify-me').click(function () {
                            //show progress
                            $.mobile.showPageLoadingMsg();
                            $.ajax({
                                cache: false,
                                type: 'POST',
                                url: '@Url.RouteUrl("BackInStockSubscribePopup", new { productVariantId = Model.ProductVariantId })',
                                data: $(this.form).serialize(),
                                dataType: 'json',
                                complete: function (data) {
                                    //hide progress
                                    $.mobile.hidePageLoadingMsg();

                                    //redirect to product details page
                                    document.location.href = "@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })";
                                }
                            });
                            return false;
                        });
                    });
                    </script>
                }
            </div>
        </div>
    </div>
}
